package com.example.base.cons.mvvm

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch

open class BaseViewModel :ViewModel(){
    fun <T> httpReq(s:suspend()->BaseModel<T>,success:(T)->Unit){
        viewModelScope.launch {
            try {
                val data =s.invoke()
                if (data.code == 200){
                    success.invoke(data.data)
                }else{
                    Log.d("aa", data.message)
                }
            }catch (e:Exception){
                Log.d("aa", e.message.toString())
            }
        }
    }
}